import { ApiProperty, getSchemaPath } from "@nestjs/swagger";
import { CrudValidationGroups } from "@nestjsx/crud";
import { IsOptional, IsString, ValidateNested } from "class-validator";
import { Column, Entity, ManyToOne, PrimaryGeneratedColumn } from "typeorm";
import { file } from "./about/file";
import { BaseEntity } from "./base.entity";
import { Group } from "./group.entity";
import { Village } from "./village.entity";

const { CREATE, UPDATE } = CrudValidationGroups;


@Entity()
export class VillageMeeting extends BaseEntity {

  @ApiProperty({
    description: '村会议 -主键',
    required: false
  })
  @PrimaryGeneratedColumn()
  id ?: number;

  @ApiProperty({
    example: 1,
    description: '所属村',
    required: true,
    oneOf: [
      {
        type: 'Number'
      },
      {
        $ref: getSchemaPath(() => Village)
      }
    ]
  })
  @ManyToOne(() => Village, Village => Village.villageMeeting, {
    eager: true
  })
  village: Number | Village

  @ApiProperty({
    example: 1,
    description: '所属村',
    required: true,
  })
  @ManyToOne(
    () => Group,
    Group => Group.villageMeeting,
    {
      eager: true,
    },
  )
  group: Number | Group;
  

  @ApiProperty({
    example: '会议名字',
    description: '会议名字',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
  })
  name: string

  @ApiProperty({
    example: '会议标题',
    description: '会议标题',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "char",
    length: 255,
  })
  title: string

  @ApiProperty({
    example: '会议时间',
    description: '会议时间',
    required: true
  })
  @IsString({ always: true })
  @Column({
    type: "date"
  })
  time: Date

  @ApiProperty({
    example: '会议地点',
    description: '会议地点',
    required: true
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: "char",
    length: 255,
    nullable: true
  })
  location: string

  @ApiProperty({
    example: '会议内容',
    description: '会议内容',
    required: true
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: "text",
    nullable: true
  })
  content: string
  
  @ApiProperty({
    example: '主持人',
    description: '主持人',
    required: true
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: "text",
    nullable: true
  })
  host: string

  @ApiProperty({
    example: '记录人',
    description: '记录人',
    required: true
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: "text",
    nullable: true
  })
  recorder: string

  @ApiProperty({
    example: '参与人员',
    description: '参与人员',
    required: true
  })
  @IsString({ always: true })
  @IsOptional({ always: true })
  @Column({
    type: "text",
    nullable: true
  })
  actor: string

  @ApiProperty({
    example: '相关文件',
    description: '相关文件',
    required: true,
    type: file
  })
  @ValidateNested()
  @IsOptional({ always: true })
  @Column({
    type: "simple-json",
    nullable: true,
  })
  relatedDocuments: file [] 
}